package promote.brozen.utils.tuples;

import lombok.Data;

import java.io.Serializable;

/**
 * @author Brozen
 * @date 2019/7/4 11:09 AM
 */
@Data
public class Tuple<A, B> implements Serializable {

    private A a;

    private B b;

    public Tuple() {
    }

    public Tuple(A a, B b) {
        this.a = a;
        this.b = b;
    }

    @Override
    public int hashCode() {
        return (a == null ? 0 : a.hashCode()) * 31 + (b == null ? 0 : b.hashCode());
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof Tuple)) {
            return false;
        }

        Tuple other = (Tuple) obj;
        return equals(this.a, other.a) && equals(this.b, other.b);

    }

    private boolean equals(Object obj1, Object obj2) {
        return obj1 == obj2 || (obj1 != null && obj1.equals(obj2));
    }

}
